import java.util.ArrayList;
import java.util.List;

public class Student {
    String name;
    List<Course> myCourses = new ArrayList<>();

    public Student(String name) {
        this.name = name;
    }


    public void selectCourse(Course course) {
        if (myCourses.contains(course)) {
            System.out.println(name + "选课失败：已选《" + course.name + "》");
            return;
        }
        if (course.select()) {
            myCourses.add(course);
            System.out.println(name + "选课成功：《" + course.name + "》（教师：" + course.teacher.name + "）");
        } else {
            System.out.println(name + "选课失败：《" + course.name + "》已选满");
        }
    }


    public void dropCourse(Course course) {
        if (myCourses.remove(course) && course.drop()) {
            System.out.println(name + "退课成功：《" + course.name + "》");
        } else {
            System.out.println(name + "退课失败：未选《" + course.name + "》");
        }
    }


    public void showCourses() {
        System.out.println("\n" + name + "的已选课程：");
        for (Course c : myCourses) {
            System.out.printf("《%s》- 教师：%s\n", c.name, c.teacher.name);
        }
    }
}